﻿/*----------------------------------------------------------------
  //Copyright (C) 2012 赵国伟
  //文件名：PurviewResourceManage.cs
  //文件功能描述：权限资源管理
  //创建人：赵国伟
  //生成时间：2012/03/17 16:15:00
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Shopping.Common;
using Shopping.Model;
using Shopping.DAL;

namespace Shopping.BLL
{
    public class PurviewResourceManage
    {
        private readonly DALPurviewGroups dalGroups = new DALPurviewGroups();
        private readonly DALPurviewOperates dalOperates = new DALPurviewOperates();
        private readonly DALPurviewResources dalResources = new DALPurviewResources();
        private readonly DALPrivileges dalPrivileges = new DALPrivileges();
        private readonly DALPrivilegeOperates dalPrivilegeOperate = new DALPrivilegeOperates();
        private readonly DALPurviewRole dalRoles = new DALPurviewRole();
        
        


        #region "返回指定状态下的所有分组信息； by 赵国伟 2012-03-18"
        /// <summary>
        /// 返回指定状态下的所有分组信息；
        /// </summary>
        /// <param name="IsAvailable"></param>
        /// <returns></returns>
        public List<PurviewGroups> QueryAllGroups(bool IsAvailable)
        {
            string cond = "";
            if (IsAvailable)
                cond = "Status='" + Status.正用.ToString() + "'";
            else
                cond = "Status<>'" + Status.已删除.ToString() + "'";

            return dalGroups.QueryList(cond, "OrderValue ,CreateDate asc");
        }
        #endregion

        #region "返回所有的分组信息并存为Hash结构； by 赵国伟 2012-03-18"
        /// <summary>
        /// 返回所有的分组信息并存为Hash结构；
        /// </summary>
        /// <returns></returns>
        public Dictionary<int, string> QueryAllGroupsToHash()
        {
            List<PurviewGroups> listOfData = QueryAllGroups(false);
            Dictionary<int,string> dict = new Dictionary<int,string>();
            foreach (PurviewGroups g in listOfData)
                dict.Add(g.PurviewGroupID, g.GroupName);
            return dict;
        }
        #endregion

        #region "保存分组信息； by 赵国伟 2012-03-18"
        /// <summary>
        ///保存分组信息；
        /// </summary>
        /// <param name="groupInfo">分组信息</param>
        /// <returns></returns>
        public ReturnValue SaveGroup(PurviewGroups groupInfo)
        {
            ReturnValue ret = new ReturnValue(ResultType.Fail);
            if (groupInfo == null)
            {
                ret.Message = "分组不能为空！";
            }
            else
            {
                if (groupInfo.PurviewGroupID <= 0)
                {
                    #region "添加的情况"
                    if (dalGroups.QueryList(1, "GroupName='" + groupInfo.GroupName + "' and Status<>'"+Status.已删除.ToString()+"' ", "") != null)
                        ret.Message = "分组名称重复!";
                    else
                    {
                        if (dalGroups.Add(groupInfo) > 0)
                        {
                            ret.Result = ResultType.Success;
                            ret.Message = "保存成功！";
                        }
                        else
                            ret.Message = "保存失败";
                    }
                    #endregion
                }
                else
                {
                    #region "修改的情况"
                    if (dalGroups.QueryList(1, "GroupName='" + groupInfo.GroupName + "' and Status<>'" + Status.已删除.ToString() + "'  and PurviewGroupID <>" + groupInfo.PurviewGroupID + "", "") != null)
                        ret.Message = "分组名称重复!";
                    else
                    {
                        PurviewGroups oldGroupInfo = dalGroups.GetModel(groupInfo.PurviewGroupID);
                        groupInfo.CreateDate = oldGroupInfo.CreateDate;
                        if (dalGroups.Update(groupInfo) > 0)
                        {
                            ret.Result = ResultType.Success;
                            ret.Message = "保存成功！";
                        }
                        else
                            ret.Message = "保存失败";
                    }
                    #endregion
                }
            }

            return ret;
        }
        #endregion

        #region "查询一条分组信息； by 赵国伟 2012-03-18"
        /// <summary>
        /// 查询一条分组信息；
        /// </summary>
        /// <param name="groupId"></param>
        /// <returns></returns>
        public PurviewGroups GetGroupInfo(int groupId)
        {
            return dalGroups.GetModel(groupId);
        }
        #endregion

        #region "更新指定分组的状态； by 赵国伟 2012-03-18"
        /// <summary>
        /// 更新指定分组的状态；
        /// </summary>
        /// <param name="groupId"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public int UpdateGroupStatus(int groupId, Status status)
        {
            return dalGroups.UpdateStatus(groupId, status.ToString());
        }
        #endregion

        #region "获取指定状态下的所有分组信息并输出为下拉选项； by 赵国伟 2012-03-19"
        /// <summary>
        /// 获取指定状态下的所有分组信息并输出为下拉选项；
        /// </summary>
        /// <param name="IsAvailable"></param>
        /// <param name="defaultValue"></param>
        /// <returns></returns>
        public static string GetGroupsToSelectOption(bool IsAvailable,string defaultValue)
        {
            PurviewResourceManage bllResource = new PurviewResourceManage();
            List<PurviewGroups> listData = bllResource.QueryAllGroups(IsAvailable);
            StringBuilder sb = new StringBuilder(500);
            if (listData != null)
            {
                foreach (PurviewGroups datainfo in listData)
                {
                    sb.Append("<option value=\"");
                    sb.Append(datainfo.PurviewGroupID);
                    sb.Append("\" ");
                    if (defaultValue == datainfo.PurviewGroupID.ToString())
                    {
                        sb.Append(" Selected ");
                    }
                    if (datainfo.Status != Status.正用.ToString())
                    {
                        sb.Append(" style=\"color:gray;\" ");
                    }
                    sb.Append(">");
                    sb.Append(datainfo.GroupName);
                    sb.Append("</option>");
                }
            }
            return sb.ToString();
        }
        #endregion



        #region "保存权限资源信息； by 赵国伟 2012-03-18"
        /// <summary>
        /// 保存权限资源信息；
        /// </summary>
        /// <param name="res"></param>
        /// <returns></returns>
        public ReturnValue SaveResource(PurviewResources res, string selectOperateIds)
        {
            ReturnValue ret = new ReturnValue();
            if (res == null)
            {
                ret.Message = "菜单资源信息不能为空";
                return ret;
            }
            ////=====================开始准备保存数据；===
            if (res.PurviewResourceID > 0)
            {
                //编辑的情况；
                PurviewResources source = dalResources.GetModel(res.PurviewResourceID);
                if (source == null)
                {
                    ret.Message = "您要编辑的资源菜单信息不存在或已被删除！";
                    return ret;
                }
                if (res.ResourceName.Trim() != source.ResourceName.Trim())
                {
                    if (dalResources.QueryList(1,"ResourceName='"+res.ResourceName+"' and PurviewResourceID<>"+res.PurviewResourceID,"") != null)
                    {
                        ret.Message = "资源菜单名称已经存在，请重新输入！";
                        return ret;
                    }
                }
                res.CreateDate = DateTime.Now;
            }
            else
            {
                //新增的情况；
                if (dalResources.QueryList(1, "ResourceName='" + res.ResourceName + "'", "") != null)
                {
                    ret.Message = "资源菜单名称已经存在，请重新输入！";
                    return ret;
                }
            }
            return dalResources.SaveResource(res, selectOperateIds);
        }
        #endregion

        #region "查询一条权限资源信息； by 赵国伟 2012-03-18"
        /// <summary>
        /// 查询一条权限资源信息；
        /// </summary>
        /// <param name="resId"></param>
        /// <returns></returns>
        public ResourceInfo GetResource(int resId)
        {
            PurviewResources resinfo = dalResources.GetModel(resId);
            ResourceInfo r = null;
            if (resinfo != null)
            {
                r = new ResourceInfo();
                r.Res = resinfo;
                r.GroupInfo = new IDNameObj();
                r.GroupInfo.ID = r.Res.PurviewGroupID;
                r.GroupInfo.Name = dalGroups.GetGroupName(resinfo.PurviewGroupID);
                r.Operates = dalOperates.QueryListToBase(resId);
            }
            return r;
        }
        #endregion

        #region "返回指定状态下的所有资源 by 赵国伟 2012-03-18"
        /// <summary>
        /// 返回指定状态下的所有资源
        /// </summary>
        /// <param name="IsAvailable"></param>
        /// <param name="IsLoadOperates"></param>
        /// <returns></returns>
        public List<ResourceInfo> QueryAllRes(bool IsAvailable,  bool IsLoadOperates)
        {
            string cond = "";
            if (IsAvailable)
                cond = "Status='" + Status.正用.ToString() + "'";
            else
                cond = "Status<>'" + Status.已删除.ToString() + "'";

            List<PurviewResources> listOfRes = dalResources.QueryList(cond, "PurviewGroupID,OrderValue,PurviewResourceID ");
            List<ResourceInfo> listOfData = null;
            if (listOfRes != null)
            {
                listOfData = new List<ResourceInfo>();
                Dictionary<int, string> dictGroup = QueryAllGroupsToHash();
                foreach (PurviewResources resinfo in listOfRes)
                {
                    ResourceInfo data = new ResourceInfo();
                    data.Res = resinfo;
                    data.GroupInfo = new IDNameObj();
                    data.GroupInfo.ID = resinfo.PurviewGroupID;
                    if (dictGroup.ContainsKey(resinfo.PurviewGroupID))
                        data.GroupInfo.Name = dictGroup[resinfo.PurviewGroupID];
                    if (IsLoadOperates)
                        data.Operates = dalOperates.QueryListToBase(resinfo.PurviewResourceID);
                    listOfData.Add(data);
                }

            }
            return listOfData;
        }
        #endregion

        #region "查询指定员工拥有的资源； by 赵国伟 2012-03-26"
        /// <summary>
        /// 查询指定员工拥有的资源；
        /// </summary>
        /// <param name="employeeId"></param>
        /// <returns></returns>
        public List<ResourceInfo> QueryEmployeeRes(int employeeId)
        {
            string cond = "PurviewResourceID in (";
            cond += "Select PurviewResourceID from Privileges where PrivilegeID in (";
            cond += "Select PrivilegeID from R_PurviewRole_Privileges where PurviewRoleID in ";
            cond += "(";
            cond += "Select  PurviewRoleID from R_Employees_PurviewRole where EmployeeID=" + employeeId;
            cond += ")";
            cond += ")";
            cond += ")";
            cond += " and Status='" + Status.正用.ToString() + "'";

            List<PurviewResources> listOfRes = dalResources.QueryList(cond, "PurviewGroupID,OrderValue,PurviewResourceID ");
            List<ResourceInfo> listOfData = null;
            if (listOfRes != null)
            {
                listOfData = new List<ResourceInfo>();
                Dictionary<int, string> dictGroup = QueryAllGroupsToHash();
                foreach (PurviewResources resinfo in listOfRes)
                {
                    ResourceInfo data = new ResourceInfo();
                    data.Res = resinfo;
                    data.GroupInfo = new IDNameObj();
                    data.GroupInfo.ID = resinfo.PurviewGroupID;
                    if (dictGroup.ContainsKey(resinfo.PurviewGroupID))
                        data.GroupInfo.Name = dictGroup[resinfo.PurviewGroupID];
                    listOfData.Add(data);
                }
            }
            return listOfData;
        }
        #endregion


        #region "获取用户当前的后台菜单；"
        /// <summary>
        /// 获取用户当前的后台菜单；
        /// </summary>
        /// <param name="employeeId"></param>
        /// <param name="url"></param>
        /// <param name="dictGroups"></param>
        /// <param name="listOfCurRes"></param>
        /// <param name="curGroupID"></param>
        public void GetEmployeeMenus(int employeeId, string url, out Dictionary<int, string> dictGroups, out Dictionary<int, string> dictGroupUrls
            , out List<PurviewResources> listOfCurRes, out int curGroupID)
        {
            dictGroups = new Dictionary<int, string>();
            dictGroupUrls = new Dictionary<int, string>();
            curGroupID = 0;
            List<ResourceInfo> listOfAllUserRes = QueryEmployeeRes(employeeId);

            string[] tmpUrl = url.Split(new char[] { '?'});
            tmpUrl[0] = tmpUrl[0].ToLower();
            Dictionary<int,List<PurviewResources>> dictRes = new Dictionary<int,List<PurviewResources>>();
            dictRes.Add(curGroupID, new List<PurviewResources>());
            if (listOfAllUserRes != null)
            {
                foreach (ResourceInfo res in listOfAllUserRes)
                {
                    if (!dictGroups.ContainsKey(res.GroupInfo.ID))
                    {
                        dictGroups.Add(res.GroupInfo.ID, res.GroupInfo.Name);
                        dictGroupUrls.Add(res.GroupInfo.ID, res.Res.ResourceUrl);
                    }

                    if (!dictRes.ContainsKey(res.GroupInfo.ID))
                        dictRes.Add(res.GroupInfo.ID, new List<PurviewResources>());
                    dictRes[res.GroupInfo.ID].Add(res.Res);
                    if (res.Res.ResourceUrl.ToLower().IndexOf(tmpUrl[0]) >= 0)  //根据Url调整默认组号；
                        curGroupID = res.GroupInfo.ID;
                }
            }
            listOfCurRes = dictRes[curGroupID];
        }
        #endregion




        #region "查询指定的角色信息； by 赵国伟 2012-03-20"
        /// <summary>
        /// 查询指定的角色信息；
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public RoleInfo GetRole(int roleId)
        {
            RoleInfo r = null;
            PurviewRole pr = dalRoles.GetModel(roleId);
            if (pr != null)
            {
                r = new RoleInfo();
                r.Role = pr;
                r.UsedCounts = dalRoles.GetUsedCounts(roleId);
                List<Privileges> listOfP = dalPrivileges.QueryList("PrivilegeID in(Select PrivilegeID from R_PurviewRole_Privileges Where PurviewRoleID=" + roleId + ")", "");
                Dictionary<int, List<int>> dictO = dalPrivilegeOperate.QueryOperateIds(new List<string>() { roleId.ToString() });
                if (listOfP != null)
                {
                    r.Privileges = new List<PrivilegeInfo>();
                   
                    foreach (Privileges p in listOfP)
                    {
                        PrivilegeInfo pi = new PrivilegeInfo();
                        pi.ResourceID = p.PurviewResourceID;
                        if (dictO.ContainsKey(p.PrivilegeID))
                            pi.Operates = dictO[p.PrivilegeID];
                        r.Privileges.Add(pi);
                    }
                }
            }
            return r;
        }
        #endregion

        #region "查询所有的角色信息 by 赵国伟 2012-03-20"
        /// <summary>
        /// 查询所有的角色信息
        /// </summary>
        /// <param name="IsAvailable"></param>
        /// <param name="IsLoadCounts"></param>
        /// <param name="IsLoadPrivilege"></param>
        /// <returns></returns>
        public List<RoleInfo> QueryAllRoles(bool IsAvailable, bool IsLoadCounts, bool IsLoadPrivilege)
        {
            string cond = "";
            if (IsAvailable)
                cond = "Status='" + Status.正用.ToString() + "'";
            List<PurviewRole> listOfRole = dalRoles.QueryList(cond, "PurviewRoleID  "); 
            List<RoleInfo> listOfData = null;
            if (listOfRole != null)
            {
                listOfData = new List<RoleInfo>();
                Dictionary<int, int> dictCounts = null;
                if (IsLoadCounts)
                    dictCounts = dalRoles.QueryUsedCounts();
                else
                    dictCounts = new Dictionary<int, int>();
                foreach(PurviewRole roleInfo in listOfRole)
                {
                    RoleInfo data = new RoleInfo();
                    data.Role = roleInfo;
                    if (dictCounts.ContainsKey(roleInfo.PurviewRoleID))
                        data.UsedCounts = dictCounts[roleInfo.PurviewRoleID];

                    listOfData.Add(data);
                }
            }
            return listOfData;
        }
        #endregion

        #region "保存角色信息； by 赵国伟 2012-03-19"
        /// <summary>
        /// 保存角色信息；
        /// </summary>
        /// <param name="roleInfo"></param>
        /// <param name="privileges"></param>
        /// <returns></returns>
        public ReturnValue SaveRole(PurviewRole roleInfo, List<PrivilegeInfo> privilege)
        {
            ReturnValue ret = new ReturnValue();
            if (roleInfo.PurviewRoleID <=0)
            {
                if (dalRoles.QueryList(1, "RoleName='" + roleInfo.RoleName + "'", "") != null)
                {
                    ret.Message = "角色名称重复！";
                    return ret;
                }
                roleInfo.CreateDate = DateTime.Now;
                roleInfo.LastModifyDate = DateTime.Now;
            }
            else
            {
                PurviewRole oldinfo = dalRoles.GetModel(roleInfo.PurviewRoleID);
                roleInfo.CreateDate = oldinfo.CreateDate;
                roleInfo.LastModifyDate = DateTime.Now;
                if (roleInfo.RoleName != oldinfo.RoleName)
                {
                    if (dalRoles.QueryList(1, "RoleName='" + roleInfo.RoleName + "'", "") != null)
                    {
                        ret.Message = "角色名称重复！";
                        return ret;
                    }
                }
            }
            return dalRoles.SaveRole(roleInfo, privilege);
        }
        #endregion

        #region "查询角色信息 并输出为复选框选项； by 赵国伟 2012-03-20"
        /// <summary>
        /// 查询角色信息 并输出为复选框选项；
        /// </summary>
        /// <param name="chkObjectName"></param>
        /// <param name="defaultValue"></param>
        /// <param name="maxLineNumber"></param>
        /// <returns></returns>
        public static string GetRolesToCheckObject(string chkObjectName, string defaultValue, int maxLineNumber)
        {
            PurviewResourceManage bllRes = new PurviewResourceManage();
            List<RoleInfo> datalist = bllRes.QueryAllRoles(true,false,false);
            StringBuilder sb = new StringBuilder(500);
            if (datalist != null)
            {
                defaultValue = "," + defaultValue + ",";
                int i = 1;
                foreach (RoleInfo datainfo in datalist)
                {
                    sb.Append("<label for=\"chkOfRole" + datainfo.Role.PurviewRoleID + "\">");
                    sb.Append("<input name=\"");
                    sb.Append(chkObjectName);
                    sb.Append("\" type=\"checkbox\" value=\"");
                    sb.Append(datainfo.Role.PurviewRoleID);
                    sb.Append("\"  id=\"chkOfRole" + datainfo.Role.PurviewRoleID + "\" ");
                    if (defaultValue.IndexOf("," + datainfo.Role.PurviewRoleID + ",") >= 0)
                        sb.Append(" checked ");
                    sb.Append("/>");
                    sb.Append(datainfo.Role.RoleName);
                    sb.Append("</label>");
                    sb.Append("&nbsp;");
                    if (maxLineNumber > 0)
                    {
                        if (i % maxLineNumber == 0)
                        {
                            sb.Append(" <br>");
                        }
                    }
                    i++;
                }
            }
            return sb.ToString();
        }
        #endregion

        #region "删除一条角色信息； by 赵国伟 2012-03-25"
        /// <summary>
        /// 删除一条角色信息；
        /// </summary>
        /// <param name="roleId"></param>
        /// <returns></returns>
        public ReturnValue DeleteRole(int roleId)
        {
            return dalRoles.DeleteRole(roleId);
        }
        #endregion


        #region "获取资源被使用的统计数；by 赵国伟 2012-03-24"
        /// <summary>
        /// 获取资源被使用的统计数；
        /// </summary>
        /// <returns></returns>
        public Dictionary<int, int> QueryOperatesUsedCounts()
        {
            return dalOperates.QueryUsedCounts();
        }
        #endregion

        #region "查询所有的资源操作信息 by 赵国伟 2012-03-24"
        public List<PurviewOperates> QuerAllBaseOperates()
        {
            return dalOperates.QueryList("", "OrderValue,PurviewOperateID");
        }
        /// <summary>
        /// 查询所有的资源操作信息
        /// </summary>
        /// <returns></returns>
        public List<PurviewOperateInfo> QuerAllOperates()
        {
            List<PurviewOperates> listOfOperates = dalOperates.QueryList("", "OrderValue,PurviewOperateID");
            List<PurviewOperateInfo> listOfData = null;
            if (listOfOperates != null)
            {
                Dictionary<int, int> dictCounts = dalOperates.QueryUsedCounts();
                listOfData = new List<PurviewOperateInfo>();
                foreach (PurviewOperates operateInfo in listOfOperates)
                {
                    PurviewOperateInfo o = new PurviewOperateInfo();
                    o.OperateInfo = operateInfo;
                    if (dictCounts.ContainsKey(operateInfo.PurviewOperateID))
                        o.UsedCounts = dictCounts[operateInfo.PurviewOperateID];
                    listOfData.Add(o);   
                }
            }
            return listOfData;
        }
        #endregion

        #region "查询指定的一条资源操作信息； by 赵国伟 2012-03-24"
        /// <summary>
        /// 查询指定的一条资源操作信息；
        /// </summary>
        /// <param name="operateId"></param>
        /// <returns></returns>
        public PurviewOperateInfo GetOperate(int operateId)
        {
            PurviewOperateInfo o = null;
            PurviewOperates data = dalOperates.GetModel(operateId);
            if(data != null)
            {
                o = new PurviewOperateInfo();
                o.OperateInfo = data;
                o.UsedCounts = dalOperates.GetUsedCounts(operateId);
            }
            return o;
        }
        #endregion

        #region "保存资源操作信息  by 赵国伟 2012-03-24"
        /// <summary>
        /// 保存资源操作信息
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public ReturnValue SaveOperate(PurviewOperates o)
        {
            ReturnValue ret = new ReturnValue(ResultType.Fail, "保存失败");
            if (o == null)
            {
                ret.Message = "资源操作信息不能为空！";
                return ret;
            }
            if (o.PurviewOperateID <= 0)
            {
                #region "添加的情况"
                if (dalOperates.QueryList(1, "OperateName='" + o.OperateName + "'", "") != null)
                    ret.Message = "资源操作名称重复!";
                else
                {
                    o.CreateDate = DateTime.Now;
                    if (dalOperates.Add(o) > 0)
                    {
                        ret.Result = ResultType.Success;
                        ret.Message = "保存成功！";
                    }
                }
                #endregion
            }
            else
            {
                #region "修改的情况"
                if (dalOperates.QueryList(1, "OperateName='" + o.OperateName + "'  and PurviewOperateID <>" + o.PurviewOperateID + "", "") != null)
                    ret.Message = "资源操作名称重复!";
                else
                {
                    PurviewOperates oldOperate = dalOperates.GetModel(o.PurviewOperateID);
                    o.CreateDate = oldOperate.CreateDate;
                    if (dalOperates.Update(o) > 0)
                    {
                        ret.Result = ResultType.Success;
                        ret.Message = "保存成功！";
                    }
                }
                #endregion
            }
            return ret;
        }
        #endregion

        #region "获取指定状态下的资源操作数据；并输出为多选框选项； by 赵国伟 2012-03-24"
        /// <summary>
        /// 获取指定状态下的资源操作数据；并输出为多选框选项；
        /// </summary>
        /// <param name="chkName">对象名称</param>
        /// <param name="defaultValue">多个默认值请以,分割</param>
        /// <param name="MaxLineNumber">一行显示数量 0为不限</param>
        /// <returns></returns>
        public static string GetOperatesToCheckOption(string chkName,  string defaultValue, int maxLineNumber)
        {
            PurviewResourceManage bllRes = new PurviewResourceManage();
            List<PurviewOperates> data = bllRes.QuerAllBaseOperates();
            StringBuilder sb = new StringBuilder(1500);
            if (data != null)
            {
                defaultValue = "," + defaultValue + ",";
                int i = 1;
                foreach (PurviewOperates datainfo in data)
                {
                    sb.Append("<label for=\"");
                    sb.Append("chkoperate");
                    sb.Append(datainfo.PurviewOperateID);
                    sb.Append("\" style=\"cursor:hand;\"><input name=\"");
                    sb.Append(chkName);
                    sb.Append("\" id=\"");
                    sb.Append("chkoperate");
                    sb.Append(datainfo.PurviewOperateID);
                    sb.Append("\" type=\"checkbox\" value=\"");
                    sb.Append(datainfo.PurviewOperateID);
                    sb.Append("\" ");

                    if (defaultValue.IndexOf("," + datainfo.PurviewOperateID + ",") >= 0)
                        sb.Append(" checked ");

                    sb.Append("/>");
                    sb.Append(datainfo.OperateName);
                    sb.Append("</label>");
                    sb.Append("&nbsp;");
                    if (maxLineNumber > 0)
                    {
                        if (i % maxLineNumber == 0)
                        {
                            sb.Append(" <br>");
                        }
                    }
                    i++;
                }
            }
            return sb.ToString();

        }
        #endregion









    }
}
